<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
	<body style="height: 100%; width: 100%; overflow: hidden; border: none;">
		<script type="text/javascript">
			$("document").ready(function(){
				$("#adminPopRoleid").combobox({
					valueField:'id', //值字段
				    textField:'rolename', //显示的字段
				    url:'${pageContext.request.contextPath}/sys/role.do?unDisabled',
				    panelHeight:'auto',
				    required:true,
					editable:false,//不可编辑，只能选择
					onChange:function(n,o){
					//var val = $('#adminPopRoleid').combobox('getText');
						//alert(val);
						//alert(n);
					}
				});
				
				//判断是否用 重名的 用户名
				$("#adminPopWindowUsername").change(function(){
					var _username = $(this).val();
					if("" != _username){
						$.ajax({
							type:"post",
							url:"${pageContext.request.contextPath}/sys/admin.do?judge",
							data:{
								username:_username
							},
							dataType:"json",
							success:function(data){
								if(data.msg == false ){
									$.messager.alert("提示","该用户已经存在，请重新填写","info");
									$("#adminPopWindowUsername").val("");
								}
							}
						});
					}
				})
			});
			
			function addOrUpdateUser(){
				debugger;
				var r = $('#adminForm').form('validate');
				if(!r) {
					return false;
				}
				//alert($("#adminPopRoleid").val());
				//alert($('#adminPopRoleid').combobox('getText'));
				$("#adminPopRole").val($('#adminPopRoleid').combobox('getText'));//给 角色 赋值
				$.post("${pageContext.request.contextPath}/sys/admin.do?addOrUpdate",$("#adminForm").serializeArray(),function(data){
					$('#MyPopWindow').window('close');
					$('#adminTable').datagrid('reload');  
					$.messager.alert('提示',data.msg,'info');
				});
			}
			$('#adminPopPanel').panel();
		</script>
		<form id="adminForm" method="post" style="margin: 10;text-align: center;">
			<div id="adminPopPanel"  collapsible="true" style="padding:10px;">
				<div region="center" border="false" style="padding:10px;border:1px solid #ccc;">
					<input type="hidden" name="id" id="uuid">
					用 户 名：<input type="text" id ="adminPopWindowUsername" name="username" style="width: 200px;border: 1px solid #ccc;padding: 2px;" validType="length[3,30]" class="easyui-validatebox" required="true" /> <br /><br />
					真实姓名：<input type="text" name="realname" style="width: 200px;border: 1px solid #ccc;padding: 2px;" validType="length[3,30]" class="easyui-validatebox" required="false" /> <br /><br />
					角     色：<input name="roleid" id="adminPopRoleid" style="width: 200px;border: 1px solid #ccc;padding: 2px;"  /><br /><br />
					禁     用：<input type="radio" name="isdisabled" id="isdisabled" value="0"  />是<input type="radio" name="isdisabled" id="isdisabled" value="1"  />否
					<input name="role" id="adminPopRole" type="hidden" /><br />
					<br />
				</div>
				<div region="south" border="false" style="text-align:right;height:30px;line-height:30px;">
					<a href="#" id="btn-back" onclick="closeWindow();" class="easyui-linkbutton" iconCls="icon-back">返回</a>
					<a href="#" id="btn-add" onclick="addOrUpdateUser();" class="easyui-linkbutton" iconCls="icon-save">保存</a>
				</div>
			</div>
		</form>
	</body></html>